window.onload = function(){

	var cb = {

		Echarts:{


			//创建一个图表实例
	    	qushiEcharts:echarts.init(document.getElementById('Echarts')),
	    	// 指定图表的配置项和数据
	    	option:{
				  // title: {
				  //     text: '十天'
				  // },
				  tooltip: {},
				  legend: {

				  	  show:false,
				      data:[
				      	{name:'转单数'},
							],
					  left:'auto'
				  },
				  xAxis: {
				      data: [
								 {value:"北京"},
								 {value:"上海"},
								 {value:"天津"},
								 {value:"秦皇岛"},
								
							],

							axisLabel:{

									show:true,
									color:'rgb(180,180,180)',
									interval:0,
								}

				  },
				  yAxis: {
							splitLine:{

								show: true,
								lineStyle:{
									 color: ['rgba(255,255,255,0.4)'],
									 width: 1,
									 type: 'dashed'
								 }
							},
							axisLabel:{
								show:true,
								color:'rgb(180,180,180)'
							}
						},
				  series: [
			  		{
				      name: '转单数',
				      type: 'bar',
				      data: [15, 30, 46, 20],
					  label:{show:true},
					  barWidth:15,
					  showBackground:true

				  	}],
					grid:{
						show:'true',
						borderColor:'transparent',
						backgroundColor:'rgba(255,255,255,0.2)',
						bottom:'25',
						height:'70%',
						left:'35'
					},

			},
			// 使用刚指定的配置项和数据显示图表。
			setOption:function(){
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        


				var self = this

				this.echartsReset()

				$(window).resize(function(){

					self.echartsReset()

					
				})
				
			},

			//echartsReset
			echartsReset:function(){


				var h = $('#Echarts').height()

				var w = $('#Echarts').width() * 80

				this.qushiEcharts.resize(

					{
						width: w,
						height: h

					}
				)

				this.qushiEcharts.setOption(this.option);

			}

    	},


    	qushiEcharts:{


			//创建一个图表实例
	    	qushiEcharts:echarts.init(document.getElementById('EchartsDay')),
	    	// 指定图表的配置项和数据
	    	option:{
				  // title: {
				  //     text: '十天'
				  // },
				  tooltip: {},
				  legend: {show:false,left:'10'},
				  xAxis: {
				      data: [
								 {value:"北京"},
								 {value:"上海"},
								 {value:"天津"},
								 {value:"秦皇岛"},
								
							],

							axisLabel:{

									show:true,
									color:'rgb(180,180,180)',
									
								}

				  },
				  yAxis: {
							splitLine:{

								show: true,
								lineStyle:{
									 color: ['rgba(255,255,255,0.4)'],
									 width: 1,
									 type: 'dashed'
								 }
							},
							axisLabel:{
								show:true,
								color:'rgb(180,180,180)'
							}
						},
				  series: [
			  		{
				      name: '提交数',
				      type: 'line',
				      data: [15, 30, 46, 20],
					  label:{show:true},
					  barWidth:15,
					  showBackground:true,
					  smooth: true

				  	},{
				      name: '转单数',
				      type: 'line',
				      data: [15, 30, 46, 20],
					  label:{show:true,position:'bottom'},
					  barWidth:15,
					  showBackground:true,
					  smooth: true

				  	}],
					grid:{
						show:'true',
						borderColor:'transparent',
						backgroundColor:'rgba(255,255,255,0.2)',
						bottom:'25',
						height:'75%'
					},

			},
			// 使用刚指定的配置项和数据显示图表。
			setOption:function(){



				var self = this

				this.echartsReset()


				$(window).resize(function(){

					self.echartsReset()

					
				})

				
			},

			//echartsReset
			echartsReset:function(){


				var h = $('#Echarts').height()

				var w = $('#Echarts').width()

				this.qushiEcharts.resize(

					{
						width: w,
						height: h

					}
				)

				this.qushiEcharts.setOption(this.option);

			}

   		},
   		ajaxJsonp:function(obj,call){

   			$.ajax({

 				type:'get',
			  	url:'http://od.qumei.com:5000/appApi.php',
			  	data:obj,
			  	dataType:'jsonp',
			  	jsonp: 'fun',
			  	jsonCallback:'fun',
			  	success:function(json){

			  		call(json)

			  	},
			  	erro:function(err){
			  		call(err)

			  	} 	  	 				
   			})
   		},
   		getdate_day:function(){

   			var self = this;

   			self.showLoad()

   			this.ajaxJsonp({type:1},function(json){

   				if(json){


   					var data = json.data;

   					var count = data[0]['count']?data[0]['count']:0

   					var zhuanDan = data[0]['zhuanDan']?data[0]['zhuanDan']:0

	   				$('#daysub').text(count)

	   				$('#dayzd').text(zhuanDan)

	   				self.getdate_Month()


				}
   			})

   		},
   		getdate_Month:function(){

   			var self = this;

   			this.ajaxJsonp({type:12},function(json){

   				if(json){

   					var data = json.data;

   					var count = data[0]['COUNT']?data[0]['COUNT']:0

   					var zhuanDan = data[0]['zhuanDan']?data[0]['zhuanDan']:0

	   				$('#subMonth').text(count)

	   				$('#zdMonth').text(zhuanDan)

	   				self.getdate_qudaoDay()

   					

				}



				

   			})

   		},
   		getdate_qudaoDay:function(){

   			var self = this;

   			this.ajaxJsonp({type:2},function(json){

   				if(json){

   					var data = json.data;

	   				$('#qudoBox').html('')

	   				for(var i = 0 ; i < data.length ; i++){

	   					var count = data[i]['count']?data[i]['count']:0

	   					var zhuanDan = data[i]['zhuanDan']?data[i]['zhuanDan']:0

	   					$li=`<div class="qudaoDate">
								<div>${data[i]['qudao']}</div>
								<div>${count}</div>
								<div>${zhuanDan}</div>
								<div>${Math.round(zhuanDan/count*10000)/100 + '%'}</div>
							</div>`

						$('#qudoBox').append($li)
	   				}

	   				self.getdate_cityMont()

	   				
				}

   			})

   		},
   		getdate_cityMont:function(){

   			var self = this;

   			this.ajaxJsonp({type:4},function(json){

   				if(json){

   					var data = json.data

   					var data = self.arrayTransp(data)

   					// console.log('data==>',data)

   					$('#cityEachartTitle').text(data.yue[0].replace('-','年') + '月')

   					self.Echarts.option.xAxis.data = data.depName

   					self.Echarts.option.series[0].data = data.count_i

   					self.Echarts.setOption()

   					
				}

				self.getdate_heXin()

				

   			})

   		},
   		getdate_heXin:function(){

   			var self = this;

   			this.ajaxJsonp({type:3},function(json){

   				if(json){

   					var data = json.data

   					var data = self.arrayTransp(data)

   					console.log('data==>',data)

   					self.qushiEcharts.option.xAxis.data = data.date

   					self.qushiEcharts.option.series[0].data = data.count

   					self.qushiEcharts.option.series[1].data = data.zhuanDan

   					self.qushiEcharts.setOption()

   					
				}

				self.hideLoad()

				if(api){

					//api对象不为null关闭下拉刷新
					api.refreshHeaderLoadDone()
				}

   			})

   		},
   		showLoad:function(){

   			$('#tip').show()
   		},
   		hideLoad:function(){

   			$('#tip').hide()
   		},

   		arrayTransp:function(obj){


   			var keys = Object.keys(obj[0])

   			var tra = {}

   			

   			for(var i =0 ; i < keys.length ; i++){

   				tra[keys[i]] = []

   				for (var j =0 ; j < obj.length ; j++){

   					tra[keys[i]].push(obj[j][keys[i]])

   				}

   			}


   			return tra

   		},
	}

	cb.getdate_day()

	apiready = function(){

		 //每日数据明细页面跳转
	    $('#mingxi').on('click',function(){
	        api.openWin({
	                     name:'每日数据明细',
	                     url:'html/mingxi.html',
	                     animation:{type:'movein',
	                                subType:'from_right'}
	                   })
	    })
	    //百应人工页面跳转
	    $('#byrg').on('click',function(){
	        api.openWin({
	                     name:'每日数据明细',
	                     url:'byrg/index.html',
	                     animation:{type:'movein',
	                                subType:'from_right'}
	                   })
	    })
	    //设置下拉刷新
	    api.setRefreshHeaderInfo({
		    loadingImg: 'widget://image/refresh.png',
		    bgColor: '#ccc',
		    textColor: '#fff',
		    textDown: '下拉刷新...',
		    textUp: '松开刷新...'
		}, function(ret, err) {
		    //在这里从服务器加载数据，加载完成后调用api.refreshHeaderLoadDone()方法恢复组件到默认状态
		    //
		    
		    cb.getdate_day()

		});


	}


}
	
